import {history} from 'umi'
import {BsTrash} from 'react-icons/bs'

import './index.less'

function ReplyItem(props) {
  const data = props?.data

  const renderContent = () => {
    if (data.rid) {
      return <div className='reply-reply' onClick={() => {
        history.push(data.BeReplyHouseId ? {
          pathname: '/house/house',
          query: {id: data.BeReplyHouseId}
        } : {
          pathname: '/comment/comment',
          query: {id: data.BeReplyCommentId}
        })
      }}>
        <p className='content'>{data?.BeReplyContent}</p>
      </div>
    } else if (data.cid) {
      return <div className='comment-reply' onClick={() => {
        history.push({pathname: '/comment/comment', query: {id: data.cid}})
      }}>
        <img src={data?.commentPictures ? data?.commentPictures.split('|')[0] : require('@/assets/blank.png')}/>
        <div className='content'>{data?.commentTitle}</div>
      </div>
    } else {
      return <div className='house-reply' onClick={() => {
        history.push({pathname: '/house/house', query: {id: data.houseId}})
      }}>
        <img
          src={data?.houseHouseInfoPictures ? data?.houseHouseInfoPictures.split('|')[0] : require('@/assets/blank.png')}/>
        <div className='content'>{data?.houseName}</div>
      </div>
    }
  }

  const renderStatus = () => {
    if (data.status == 1) {
      return <div className='status yellow'>待审核</div>
    } else if (data.status == 3) {
      return <div className='status red'>已拒绝</div>
    } else if (data.status == 2) {
      return <div className='status green'>已同意</div>
    }
  }

  const renderReply = () => {
    if (data.rid) {
      return <div className='reply yellow'>引用回复</div>
    } else if (data.cid) {
      return <div className='reply red'>评论回复</div>
    } else {
      return <div className='reply gray'>房屋回复</div>
    }
  }

  return (
    <div className='reply-item'>
      <div className='title'>{data?.content}</div>
      {renderContent()}
      {renderStatus()}
      {renderReply()}
      <div className='delete'><span onClick={() => {
        props.handleDelete(data.id)
      }}><BsTrash/></span></div>
    </div>
  )
}

export default ReplyItem
